
<template>
  <el-dialog
    :model-value="dialogFormVisible"
    :destroy-on-close="true"
    title="主链信息"
    width="450px"
    @close="emits('closeDialog')"
  >
    <el-form ref="dialogFormRef" :model="dialogForm" :rules="rules" :label-width="formLabelWidth">
      <el-form-item
        label="主链名称"
        
        prop="chain_name"
      >
        <el-input v-model="dialogForm.chain_name" />
      </el-form-item>
      <el-form-item label="是否允许充值" >
        <el-switch v-model="dialogForm.is_deposit" />
      </el-form-item>
      <el-form-item label="是否允许提现" >
        <el-switch v-model="dialogForm.is_withdraw" />
      </el-form-item>
      <el-form-item label="id" style="display: none">
        <el-input v-model="dialogForm.chain_id" disabled />
      </el-form-item>
    </el-form>
    <template #footer>
      <span class="dialog-footer">
        <el-button @click="emits('cancel')">取消</el-button>
        <el-button
          type="primary"
          @click="submit(dialogForm)"
          :loading="btnLoading"
        >
          提交
        </el-button>
      </span>
    </template>
  </el-dialog>
</template>
<script setup>
import { ref } from "vue";
const dialogFormRef = ref(null);

defineProps({
  dialogFormVisible: {
    type: Boolean,
    default: false,
  },
  dialogForm: {
    type: Object,
    default: {
      chain_name: "",
      chain_id: "",
      is_deposit: false,
      is_withdraw: false,
    },
  },
  btnLoading: {
    type: Boolean,
    default: false,
  },
});
const emits = defineEmits(["closeDialog", "cancel", "submitForm"]);

const formLabelWidth = "120px";
// 校验
const rules = {
  chain_name: [{ required: true, message: "请输入主链名称", trigger: "blur" }],
};
// 提交
const submit = (dialogForm) => {
  dialogFormRef.value
    .validate()
    .then(async () => {
      try {
        const param = Object.assign({}, dialogForm);
        param.is_deposit = param.is_deposit ? 1 : 0;
        param.is_withdraw = param.is_withdraw ? 1 : 0;
        emits("submitForm", param);
      } catch (error) {
        console.log(error);
      }
    })
    .catch((error) => {
      console.log(error);
    });
};
</script>
